#------uds27密码算法---------------
# a = 0xAB
# b = 0x81
# c = 0x25
# d = 0xBD
# aa = ((d&0x0F)<<4)|((d&0xF0))
# bb = ((b&0x0F)<<4)|((a&0xF0)>>4)
# cc = (b&0xF0)|((c&0xF0)>>4)
# dd = ((a&0x0F)<<4)|(c&0x0F)
# print(hex(aa))
# print(hex(bb))
# print(hex(cc))
# print(hex(dd))
#------uds27密码算法---------------
while True:

    upgrade = input("输入yes为27服务 11 12使用解锁， 输入no为 27服务 01 02使用解锁，请输入yes或no：")
    if str(upgrade).lower() == "no":
        aaa = input("请输入第一位：")
        bbbb = input("请输入第二位：")
        cccc = input("请输入第三位：")
        dddd = input("请输入第四位：")
        a = "0x"+str(aaa)
        b = "0x"+str(bbbb)
        c = "0x"+str(cccc)
        d = "0x"+str(dddd)
        a = int(a,16)
        b = int(b,16)
        c = int(c,16)
        d = int(d,16)
        a = a ^ 0x54
        b = b ^ 0x56
        c = c ^ 0x78
        d = d ^ 0x99
        aa = ((d&0x0F)<<4)|((d&0xF0))
        bb = ((b&0x0F)<<4)|((a&0xF0)>>4)
        cc = (b&0xF0)|((c&0xF0)>>4)
        dd = ((a&0x0F)<<4)|(c&0x0F)
        one = hex(aa)
        two = hex(bb)
        three = hex(cc)
        four = hex(dd)
        print("计算结果如下：")
        print(one[2:])
        print(two[2:])
        print(three[2:])
        print(four[2:])

    else:
        aaa = input("请输入第一位：")
        bbbb = input("请输入第二位：")
        cccc = input("请输入第三位：")
        dddd = input("请输入第四位：")
        a = "0x" + str(aaa)
        b = "0x" + str(bbbb)
        c = "0x" + str(cccc)
        d = "0x" + str(dddd)
        a = int(a, 16)
        b = int(b, 16)
        c = int(c, 16)
        d = int(d, 16)
        a = a ^ 0x54
        b = b ^ 0x56
        c = c ^ 0x78
        d = d ^ 0x99
        aa = ((c & 0x03) << 6) | ((d & 0xFC)>>2)
        bb = ((d &0x03)<<6) | (a &0x3F)
        cc = (a &0xFC) | ((b & 0xC0)>>6)
        dd = (b & 0xFC) | (c & 0x03)
        one11 = hex(aa)
        two11 = hex(bb)
        three11 = hex(cc)
        four11 = hex(dd)
        print("计算结果如下：")
        print(one11[2:])
        print(two11[2:])
        print(three11[2:])
        print(four11[2:])



#
#
#
